{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn import datasets, decomposition, manifold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 使用sklearn自带的鸢尾花分类数据\n",
    "def load_data():\n",
    "    iris = datasets.load_iris()\n",
    "    return iris.data,iris.target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "def test_PCA(*data):\n",
    "    x,y = data\n",
    "    pca = decomposition.PCA()\n",
    "    pca.fit(x)\n",
    "    # explained_variance_ratio_：返回所保留的n个成分各自的方差百分比。\n",
    "    print('explained variance ratio :{0}'.format(pca.explained_variance_ratio_))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "explained variance ratio :[0.92461621 0.05301557 0.01718514 0.00518309]\n"
     ]
    }
   ],
   "source": [
    "# 测试 显示各特征占比\n",
    "x,y = load_data()\n",
    "test_PCA(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 根据上面的结果 将数据降低至2维\n",
    "def plot_PCA(*data):\n",
    "    x,y = data\n",
    "    pca = decomposition.PCA(n_components=2)\n",
    "    pca.fit(x)\n",
    "    x_r = pca.transform(x)\n",
    "    \n",
    "    fig = plt.figure()\n",
    "    ax = fig.add_subplot(111)\n",
    "#     colors=((1,0,0),(0,1,0),(0,0,1),(0.5,0.5,0),(0,0.5,0.5),(0.5,0,0.5),(0.4,0.6,0),(0.6,0.4,0),(0,0.6,0.4),(0.5,0.3,0.2),)\n",
    "    colors=((1,0,0),(0,1,0),(0,0,1))\n",
    "    for label,color in zip(np.unique(y),colors):\n",
    "        position =y==label\n",
    "        ax.scatter(x_r[position,0],x_r[position,1],label='target={0}'.format(label),color=color)\n",
    "    \n",
    "    ax.set_xlabel('X[0]')\n",
    "    ax.set_ylabel('Y[0]')\n",
    "    ax.legend(loc='best')\n",
    "    ax.set_title('PCA')\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY0AAAEWCAYAAACaBstRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3X+UXHWZ5/H3k6aZ2BBH6aALhFQzGIwhkCgNJyzMyoILiAjy6yjThsw42muEPcCszCC9isD2WWfiGWf8gUwf9BDsxsGF8cfOoCAMEJxBsHFbB4ggku4QZKQNIRCjG5J+9o+qSqqr61bdqrq37r1Vnxfnnu6qunXr2+Heeu73+3x/mLsjIiISxrykCyAiItmhoCEiIqEpaIiISGgKGiIiEpqChoiIhKagISIioSloiIhIaAoaIk0ys0kz+62Z7TCzX5nZLWZ2YOG1M8xsg5m9ambTZvagmZ1T9v5TzMzN7C+S+QtEwlPQEInGe939QOAdQD/wP8zsQuB/A7cCi4A3A58C3lv23jXAS8AlrSuuSGMUNEQi5O7PA98FjgH+GrjB3W929+3uPuPuD7r7R4r7m9kBwIXApcASM+tPpOAiISloiETIzA4HzgJ2AocDd9R4y/nADvI1krvJ1zpEUktBQyQa3zKzl4EfAA8Cf1N4/oUa71sD3O7ue4DbgA+YWXd8xRRpjoKGSDTe5+5vcPecu38M2Fp4/pCgNxRqJf8ZGCs89W1gPvCeWEsq0gQFDZF4PAU8B1xQZZ/V5K/B/2Nm/w48Sz5oqIlKUktBQyQGnl9z4M+AT5rZn5jZ681snpmdbGYjhd3WANcBK0u2C4CzzKw3kYKL1KCgIRITd78DeD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WuPoihHgadVtWVYd+7MBxXpbAoakjpp7lFUaRR4uaSmBYlC0HxURVrbG15++WVubME8Kg888AD/+q//Wtd71q9fz5IlS1iyZAnr16+PpVwKGpI6Wb6jT3JakChUmo+qVK2gkkpjY9DXl5/Wt6+v6Ta2eoOGuzMzU/9AzXqDxksvvcR1113HI488wqOPPsp1113Htm3b6v7cmsJky7O0qfeUJCmJ1fqiNjrq3tvrc9bPSMviSk8++WT4nWNYJer973+/z58/31esWOFXXHGFn3rqqf72t7/dly9f7t/61rfc3X3Tpk1+1FFH+erVq33ZsmU+OTnpN998sy9ZssSPP/54//CHP+yXXnqpu7u/+OKLfv7553t/f7/39/f7D37wA9+0aZO/+c1v9kMPPdRXrFjhGzZsqFmu2267zQcHB/c+Hhwc9Ntuu63ivpX+DdEiTCKtF8ca3UlJa9fbuoJGDIukbdq0yY8++mh3d3/ttdd8+/bt7u4+PT3tRx55pM/MzPimTZvczPzhhx92d/fnn3/ec7mcb9261Xft2uUnn3zy3qBx8cUX+0MPPeTu7lNTU7506VJ3d7/22mt93bp1ez93dHTUV6xYMWe74IIL3N193bp1fsMNN+zd//rrr5/1/lLNBA0N7hOJ0GIWV+wunHQSvxEDA+noYtuUoCRMRMkZd+eaa65hw4YNzJs3j+eff55f/epXAORyOVatWgXAo48+yjvf+U4OOuggAC666CKefvppAO69916efPLJvcd85ZVX2LFjx5zPGhgYYCAF/0MUNEQi1MiocInR4sUwNTeIR5WcGRsbY3p6mscee4zu7m76+vr2jlQ/4IADQh1jZmaGH/7wh8yfP7/mZ61bt27O8295y1u44447OOyww3jggQf2Pr9lyxZOOeWU0H9LWEqEi0Qoy0n8tlTPSlMhLViwgFdffRWA7du386Y3vYnu7m7uv/9+pioFKOD444/nwQcfZNu2bezevZs777xz72unn346X/jCF/Y+npiYmPM5kK9pTExMzNnuuOMOAM444wzuuecetm3bxrZt27jnnns444wzGv47gyhoiEQsTLdcaZEYVprq7e3lpJNOYvny5UxMTDA+Ps4xxxzDrbfeytKlS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913Jl2ejPsRsMTMjjCz/YEPAN9JuEyZZ2YGfAXY6O5/nXR5qjGzg4s9EM3sdcB/IaXXvrt/wt0XuXsf+XP1n5sJGKCg0azPFJpVfgqcTr6HQhp9EVgAfL/QPfimpAsUxMzOM7MtwInAP5nZ3UmXqVShQ8FlwN3kk7XfcPcnki1VMDP7OvAw8FYz22Jmf5p0mQKcBKwGTi2coxOFu+M0OgS4v3Dd/4h8TqPprqxZoWlEREQkNNU0REQkNAUNEREJTUFDRERCU9AQEZHQFDRERCQ0BQ0REQlNQUMkAoWpvTeZ2UGFx28sPP5jM9tuZneV7LvGzH5e2NaUPH+/me1I65TwIqBxGiKRMbM/B97i7oNm9nfAJPmBdR9397ML+xwEjAP95GdGfQw4zt23FV5/oLD/eOv/ApHaVNMQic7ngFVmdgVwMvDZCvucQX4E8UuFQPF9srHehQigCQtFIuPur5nZVcD3gNMLj8t309TqkmmqaYhE693AC0Aqp8oWaZaChkhEzGwl+RlPVwFXmtkhFXbT1OqSaQoaIhEoTO39ZfKLB20G1lE5p3E3cHqhd9Ubyc+OnKqZfEWqUdAQicZHgM3u/v3C4xuBtwHvLN3J3V8CbiA/pfaPgOsLz4lkgrrcisTIzE6hpMttiP0fQF1uJcVU0xCJ1y5geengviCFZUP/AHgt9lKJNEg1DRERCU01DRERCU1BQ0REQlPQEBGR0BQ0REQktP8PFQyJFLI0xRMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 测试\n",
    "x,y = load_data()\n",
    "plot_PCA(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 降至1维试试\n",
    "def plot_PCA_1(*data):\n",
    "    x,y = data\n",
    "    pca = decomposition.PCA(n_components=1)\n",
    "    pca.fit(x)\n",
    "    x_r = pca.transform(x)\n",
    "    \n",
    "    fig = plt.figure()\n",
    "    ax = fig.add_subplot(111)\n",
    "#     colors=((1,0,0),(0,1,0),(0,0,1),(0.5,0.5,0),(0,0.5,0.5),(0.5,0,0.5),(0.4,0.6,0),(0.6,0.4,0),(0,0.6,0.4),(0.5,0.3,0.2),)\n",
    "    colors=((1,0,0),(0,1,0),(0,0,1))\n",
    "    for label,color in zip(np.unique(y),colors):\n",
    "        position =y==label\n",
    "        ax.scatter(x_r[position,0],[1 for i in x_r[position,0]],label='target={0}'.format(label),color=color)\n",
    "    \n",
    "    ax.set_xlabel('X[0]')\n",
    "    ax.set_ylabel('Y[0]')\n",
    "    ax.legend(loc='best')\n",
    "    ax.set_title('PCA')\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZIAAAEWCAYAAABMoxE0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3X10VfWd7/H3JyFIA1gk4CxLJHFGrEXFjEalVx2tVMBqfXa1Dq1O7ZIR9K7WuXZq5frcrNbRVbvsE2NHK5TUtmNvr06vFcVq8U59aGhTBrUqVcSgoxFBpVxHHr73j72BQ0jOOcnO5iTk88raKzm//dv7fDfm5OPev31+RxGBmZlZX1VVugAzMxvcHCRmZpaJg8TMzDJxkJiZWSYOEjMzy8RBYmZmmThIzMwsEweJWT+TtErS/5O0QdLrku6SNCpdN0PSUknvSuqU9GtJp3fZ/kRJIenLlTkCs95xkJjl45MRMQo4AmgG/qekc4F/BRYC9cBfANcAn+yy7YXAW8AFu69cs75zkJjlKCLWAL8EDgO+AdwYEf8SEW9HxNaI+HVEXLytv6SRwLnApcAkSc0VKdysFxwkZjmStD/wCWAjsD9wT4lNzgY2kJy5LCY5O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hn4jMTMzDLxGYmZmWXiIDEzs0wcJGZmlomDxMzMMvn//2GfCw2po9EAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 测试\n",
    "x,y = load_data()\n",
    "plot_PCA_1(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sklearn.decomposition.incremental_pca.IncrementalPCA"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# decomposition.PCA 需要一次性将数据加载在内存中，所以不适合大规模数据\n",
    "# 超大规模数据的情况下使用： 用法与PCA一致\n",
    "decomposition.IncrementalPCA "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
